package org.swfer.UICExtend 
{
	import org.swfer.UIC.Component;
	import org.swfer.UIC.ICycle;
	
	/**
	 * 控件生存周期.用于查看控件是否有合理dispose
	 * @author swfer
	 */
	public class LifeCycleManager implements ICycle
	{
		private var _componentArr:Array;
		
		public function LifeCycleManager() 
		{
			_componentArr = [];
			Component.lifeCycleManager = this;
		}
		
		/**
		 * inherit 控件创建时自动调用
		 * @param	target
		 */
		public function create(target:Component):void
		{
			if (_componentArr.indexOf(target) == -1) _componentArr.push(target);
		}
		
		/**
		 * inherit 控件销毁时自动调用
		 * @param	target
		 */
		public function destroy(target:Component):void
		{
			var index:int = _componentArr.indexOf(target);
			if (index == -1) return;
			
			_componentArr.splice(index, 1);
		}
		
		/**
		 * 对所有控件执行销毁动作
		 */
		public function destroyAll():void
		{
			for each (var item:Component in _componentArr) 
			{
				try {
					item.dispose();
				}catch (err:Error)
				{
					trace(err);
				}
			}
		}
		
		/**
		 * 存活的控件。
		 */
		public function get componentArr():Array 
		{
			return _componentArr;
		}
		
	}

}